/**
 * 
 */
package com.lastproject.web.bean;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import com.lastproject.dto.UserDTO;
import com.lastproject.ejb.dao.UserDAORemote;

/**
 * @author Alexandra
 *
 */

@ManagedBean
@SessionScoped
public class ForgotPasswordBean {
	
	private String providedEmail;
	
	@ManagedProperty(value = "#{userDTO}")
	private UserDTO userDTO;
	private String errorMsg;

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	@EJB
	UserDAORemote userDAO;
	
	public ForgotPasswordBean() {
		
	}
	
	public ForgotPasswordBean(UserDTO userDTO) {
		this.userDTO = userDTO;
	}

	public String getProvidedEmail() {
		return providedEmail;
	}

	public void setProvidedEmail(String providedEmail) {
		this.providedEmail = providedEmail;
	}

	public UserDTO getUserDTO() {
		return userDTO;
	}

	public void setUserDTO(UserDTO userDTO) {
		this.userDTO = userDTO;
	}
	
	public String resetPassword() {
		
		errorMsg="";
		boolean opStatus = userDAO.requestChangePassword(providedEmail);
		
		if(opStatus != true) {
			errorMsg="Please enter one of your valid email adresses specified for your account!";
			return "forgotPassword";}
		else	
			return "login";
	
		
	}

}
